function gadget:GetInfo()
   return {
      name      = "Game Over",
      desc      = "ends the game when called",
      author    = "Nemo",
      date      = "8-12-10",
      license   = "LGPL v2.0 or later",
      layer     = 0,
      enabled   = true,
   }
end

if (not gadgetHandler:IsSyncedCode()) then
  return false
end

local destroyUnit          = Spring.DestroyUnit

function GG.gameOver(victoriousTeam, vanquishedTeam)
	GG['gameEnded'] = true
	local vanquishedTeam = vanquishedTeam
	if vanquishedTeam == -1 then
		Spring.Echo("LALALA!")
		for i, teamID in ipairs(Spring.GetTeamList()) do
			if teamID ~= victoriousTeam and teamID ~= Spring.GetGaiaTeamID() then 
				vanquishedTeam = teamID
			end
		end		
	end
	--TODO: make the display nicer, add some mention of points
	Spring.Echo("Team "..victoriousTeam.." has won!")
	for _,u in ipairs(Spring.GetTeamUnits(vanquishedTeam)) do
		if GG['flags'][u] == nil then
			destroyUnit(u)
		end
	end
end

function gadget:GameFrame(t)
	if t == 9000 then --5 minute time limit for games
		GG['gameEnded'] = true
		for _,u in ipairs(Spring.GetAllUnits()) do
			local unitDefID = Spring.GetUnitDefID(u)
			local unitDef = UnitDefs[unitDefID]
			local canMove = unitDef.canMove
			if canMove == true then
				Spring.DestroyUnit(u)
			end
		end	
	end
end


